Skip to content

feat(springSecurity): add spring security in app#79

Merged
MayuriXx merged 6 commits into
mainfrom
feat/springSecurity
May 4, 2026
Merged

feat(springSecurity): add spring security in app#79
MayuriXx merged 6 commits into
mainfrom
feat/springSecurity

Conversation

@Theo-lbg

Copy link
Copy Markdown
Collaborator

No description provided.

@Theo-lbg Theo-lbg force-pushed the feat/springSecurity branch from 17b3669 to 3ca0012 Compare April 24, 2026 09:58
@Theo-lbg Theo-lbg linked an issue Apr 24, 2026 that may be closed by this pull request
@Theo-lbg Theo-lbg force-pushed the feat/springSecurity branch 4 times, most recently from 7ca2ec9 to e775d93 Compare April 24, 2026 11:48
@Theo-lbg Theo-lbg marked this pull request as ready for review April 24, 2026 11:52
Copilot AI review requested due to automatic review settings April 24, 2026 11:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces Spring Security (HTTP Basic) to protect the application’s endpoints, adds in-memory users/roles configured via properties/environment variables, and updates tests + documentation to work with authentication.

Changes:

  • Added Spring Security dependency plus a SecurityFilterChain, in-memory UserDetailsService, and BCrypt encoder.
  • Added security-related configuration properties for main and test profiles; updated integration/container tests to send Basic Auth.
  • Updated CI workflows and documentation/environment templates to reflect the new security configuration.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/main/java/com/xpeho/spring_boot_java_random_user/config/SecurityConfig.java Adds Spring Security configuration (Basic auth, stateless, in-memory users).
src/main/java/com/xpeho/spring_boot_java_random_user/config/SecurityConfigurationException.java Adds a dedicated runtime exception for security filter chain build failures.
src/main/resources/application.properties Introduces app.security.* properties backed by env vars.
pom.xml Adds spring-boot-starter-security.
src/test/resources/application-test.properties Adds test security credentials and datasource defaults for the test profile.
src/test/java/feature/SpringIntegrationTest.java Updates Cucumber integration test base to use Basic Auth.
src/test/java/com/xpeho/spring_boot_java_random_user/presentation/UserGetByIdContainerTest.java Updates container test to authenticate requests; injects security properties.
src/test/java/com/xpeho/spring_boot_java_random_user/config/SecurityConfigTest.java Adds unit tests for security helper methods and in-memory user roles.
src/test/java/com/xpeho/spring_boot_java_random_user/config/SecurityConfigurationExceptionTest.java Adds unit test for the new exception.
.github/workflows/tests.yaml Modifies how application-test.properties is prepared in CI.
.github/workflows/sonar.yaml Same CI test-properties preparation change for Sonar job.
README.md Documents security env vars and Basic Auth usage/roles.
.env.template Adds placeholders for the new Spring Security env vars.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/tests.yaml
Comment thread .github/workflows/sonar.yaml
Comment thread README.md Outdated
Comment thread README.md Outdated
@Theo-lbg Theo-lbg force-pushed the feat/springSecurity branch from e775d93 to 708523e Compare April 24, 2026 12:08
Copilot AI review requested due to automatic review settings April 24, 2026 12:27
@Theo-lbg Theo-lbg force-pushed the feat/springSecurity branch from 708523e to 5d30f44 Compare April 24, 2026 12:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@MayuriXx MayuriXx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A corriger le commentaire de copilot et c'est bon pour moi ☺️

@Theo-lbg Theo-lbg force-pushed the feat/springSecurity branch from 5d30f44 to 0058607 Compare April 27, 2026 12:12
Copilot AI review requested due to automatic review settings April 27, 2026 13:06
@Theo-lbg Theo-lbg force-pushed the feat/springSecurity branch from 0058607 to b499879 Compare April 27, 2026 13:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/sonar.yaml Outdated
@Theo-lbg Theo-lbg force-pushed the feat/springSecurity branch from b499879 to e9b3b14 Compare April 27, 2026 14:10
Theo-lbg and others added 4 commits April 29, 2026 10:51
Copilot AI review requested due to automatic review settings April 29, 2026 08:51
@MayuriXx MayuriXx force-pushed the feat/springSecurity branch from e9b3b14 to e856fe6 Compare April 29, 2026 08:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md Outdated
Comment thread .github/workflows/sonar.yaml Outdated
Comment thread src/test/java/feature/SpringIntegrationTest.java Outdated
@MayuriXx MayuriXx force-pushed the feat/springSecurity branch from a401a16 to 293c5eb Compare May 4, 2026 08:43
Copilot AI review requested due to automatic review settings May 4, 2026 08:52
@MayuriXx MayuriXx force-pushed the feat/springSecurity branch from 293c5eb to 9b2a10d Compare May 4, 2026 08:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

src/test/java/feature/SpringIntegrationTest.java:74

  • executePut is still using the unauthenticated restTemplate, unlike the GET/POST/DELETE helpers above. Since PUT /random-users/** now requires the ADMIN role, the Cucumber update scenarios that call this helper will start receiving 401/403 instead of exercising the update path.
    protected void executePut(String path, Object payload) {
        String url = "http://localhost:" + port + path;
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<Object> request = new HttpEntity<>(payload, headers);
        latestResponse = restTemplate.exchange(url, HttpMethod.PUT, request, String.class);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/resources/application.properties
Comment thread .github/workflows/tests.yaml
Comment thread .github/workflows/sonar.yaml
Comment thread src/test/resources/application-test.properties.template
@MayuriXx MayuriXx force-pushed the feat/springSecurity branch from 9b2a10d to f7bddb9 Compare May 4, 2026 08:57
Copilot AI review requested due to automatic review settings May 4, 2026 09:08
@MayuriXx MayuriXx merged commit b57bea2 into main May 4, 2026
13 checks passed
@MayuriXx MayuriXx deleted the feat/springSecurity branch May 4, 2026 09:09
@sonarqube-xpeho

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

spring.sql.init.mode=never
spring.docker.compose.enabled=false
logging.level.com.xpeho.spring_boot_java_random_user.presentation.handlers=OFF
logging.level.com.zaxxer.hikari.pool.PoolBase=ERROR
Comment on lines +35 to 37
printf '%s' "${{ secrets.APPLICATION_TEST_PROPERTIES }}" | base64 -d >> src/test/resources/application-test.properties
fi
echo "spring.sql.init.mode=never" >> src/test/resources/application-test.properties
mkdir -p src/test/resources
echo ${{ secrets.APPLICATION_TEST_PROPERTIES }} | base64 -d > src/test/resources/application-test.properties
if [ -n "${{ secrets.APPLICATION_TEST_PROPERTIES }}" ]; then
printf '%s' "${{ secrets.APPLICATION_TEST_PROPERTIES }}" | base64 -d >> src/test/resources/application-test.properties
Comment on lines +58 to +61
.requestMatchers(HttpMethod.GET, RANDOM_USERS_PATH).hasAnyRole(ADMIN_ROLE, "USER", "TEST")
.requestMatchers(HttpMethod.POST, RANDOM_USERS_PATH).hasRole(ADMIN_ROLE)
.requestMatchers(HttpMethod.PUT, RANDOM_USERS_PATH).hasRole(ADMIN_ROLE)
.requestMatchers(HttpMethod.DELETE, RANDOM_USERS_PATH).hasRole(ADMIN_ROLE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Spring security

4 participants